package Thread;

import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description: 信号量-Semaphore练习
 */
public class ThreadDemo37 {
    public static void main(String[] args) throws InterruptedException {
        //表示可用资源数为4
        Semaphore semaphore = new Semaphore(4);
        //申请一个资源，可以传参申请多个
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        //释放资源
        semaphore.release();
    }
}
